

from shopping_mall.conf import setting
import json
from os import path


def get_goods() -> list:
    file_path = path.join(setting.DB_GOOD_FILE_PATH, "good_data.json")
    file_data = open(file_path, "r")
    good_json = json.load(file_data)
    file_data.close()
    return good_json


def get_shop_cart() -> list:
    file_path = path.join(setting.DB_SHOP_CART_FILE_PATH, "shopcart_data.json")
    file_size = path.getsize(file_path)
    if file_size:
        file_data = open(file_path, "r")
        shop_cart_json = json.load(file_data)
        file_data.close()
        return shop_cart_json
    else:
        return []


def write_shop_cart(*arg):
    file_path = path.join(setting.DB_SHOP_CART_FILE_PATH, "shopcart_data.json")
    file_data = open(file_path, "w")
    json.dump(arg, file_data)
    file_data.close()

